import { WeaSearchGroup, WeaFormItem } from 'ecCom';
import { WeaSwitch } from "comsMobx"
import { observer } from 'mobx-react';

@observer
export default class CptStatistics extends React.Component {

  constructor(props){
    super(props);
    this.formParams = {};
  }

  render() {
    const { condition, form } = this.props;
    const { isFormInit } = form;
    let group = [];
    const formParamsTemp = form.getFormParams();
    for(let param in formParamsTemp){
        this.formParams[param] = formParamsTemp[param];
    }
    isFormInit && condition.map((c,i) => {
      let items = [];
      c.items.map((fields, index) => {
        let hasunderline = false;
        if (fields.viewAttr == "1" || (fields.conditionType == "BROWSER" && fields.browserConditionParam.viewAttr == "1")) {
          hasunderline = true
        }
        if (hasunderline) {
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@trf6mk@${index}`}
              label={`${fields.label}`}
              labelCol={{ span: `${fields.labelcol}` }}
              wrapperCol={{ span: `${fields.fieldcol}` }} underline>
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@ehvb8u@${index}`} fieldConfig={fields} form={form} formParams={this.formParams} />
            </WeaFormItem>),
            colSpan: 1,
          })
        } else {
          items.push({
            com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@pwingm@${index}`}
              label={`${fields.label}`}
              labelCol={{ span: `${fields.labelcol}` }}
              wrapperCol={{ span: `${fields.fieldcol}` }}>
              <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@b4dc25@${index}`} fieldConfig={fields} form={form} formParams={this.formParams} />
            </WeaFormItem>),
            colSpan: 1,
          })
        }

      });
      group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@sajv48@${i}`} needTigger={true} col={1} title={c.title} showGroup={c.defaultshow} items={items} />)
    });
    return group;
  }
}



